{% extends theme("base.html") %}
{% from theme('_comments.html') import comment_filed with context%}
{% block content %}
    <div class="alert alert-success container" role="alert">
        <h3>有什么想说的，请留下宝贵的想法。</h3>
    </div>
    <div class="container">
        {{ comment_filed(form=form,comments=comments) }}
    </div>
{% endblock %}
{% block script %}
    {{ super() }}
    <script type="text/javascript">
        $('#exampleModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget) // Button that triggered the modal
            var recipient = button.data('whatever').split('|') // Extract info from data-* attributes
            // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
            // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
            var modal = $(this)
            var name = recipient[0]
            var id = recipient[1]
            modal.find('.modal-title').text('回复' + name)
            modal.find('#parent_id').val(id)
        })
        function sub_comment() {
            var csrftoken = $('meta[name=csrf-token]').attr('content')
            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken)
                    }
                }
            });
            $.ajax({
                cache: false,
                type: "POST",
                url: "{{ url_for('api.comment') }}",	 //把表单数据发送到ajax.jsp
                data: $('#comment_form').serialize(),	 //要发送的是ajaxFrm表单中的数据
                async: false,
                error: function (request) {
                    alert("发送请求失败！");
                },
                success: function (data) {
                    if (data.status = 1) {
                        alert('评论成功');
                        location.reload();
                    }	 //将返回的结果显示到ajaxDiv中
                }
            });
        }
    </script>
{% endblock %}